<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>兑换审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/layuiadmin/style/admin.css" media="all">
<body layadmin-themealias="default" style="">
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item" style="height: 20px;line-height: 20px;">
                <div class="layui-inline" style="margin-right: 0px;">
                     <span class="layui-breadcrumb">
                        <a href="">首页/兑换审核</a>
                        </span>
                </div>
                <div class="layui-inline" style="right: 0px;position: absolute;">
                    <a class="layui-btn layui-btn-small" style="line-height:20px;margin-top:-6px;float:right" href="javascript:location.replace(location.href);" title="刷新">
                        &nbsp; <i class="layui-icon layui-icon-refresh-3" style="line-height:18px;left: 12px;top:12px;"></i> &nbsp;
                    </a>
                </div>
            </div>
        </div>
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline" style="margin-right: 0px;">
                    <label class="layui-form-label">ID</label>
                    <div class="layui-input-inline">
                        <input type="number" name="gameid"  placeholder="游戏ID"  class="layui-input">
                    </div>
                </div>
                <div class="layui-inline" style="margin-right: 0px;">
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="开始日期" name="start_time" id="start" >

                    </div>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="截止日期" name="end_time" id="end">

                    </div>
                </div>
                <div class="layui-inline" style="margin-right: 0px;">
                    <div class="layui-input-inline">
                        <select name="channel" class="">
                            <option value="">全部渠道</option>
                            <option value="0">支付宝</option>
                            <option value="1">微信</option>
                            <option value="2">银行卡</option>
                        </select>
                    </div>
                </div>
               <!-- <div class="layui-inline" style="margin-right: 0px;">
                    <div class="layui-input-inline">
                        <select name="status" class="">
                            <option value="">全部</option>
                            <option value="1">已审核</option>
                            <option value="4">提现异常</option>
                            <option value="2">已付款</option>
                        </select>
                    </div>
                </div>-->
                <input type="hidden" name="tradetype" value="{$status}" />
                <div class="layui-inline" style="margin-right: 0px;">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit="" lay-filter="LAY-user-back-search">
                        &nbsp;&nbsp;&nbsp;&nbsp;<i class="layui-icon layui-icon-search"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide" id="admin_table" lay-filter="admin_table"></table>

            <script type="text/html" id="table-status">
                {{# if(d.status =='0') { }}
                <span style="color: #ff5722">兑换中</span>
                {{# }else if(d.status =='1'){ }}
                <span style="color: #01AAED">已兑换</span>
                {{# }else { }}
                <span style="color: #2f4056">已拒绝</span>
                {{# } }}
            </script>
            <script type="text/html" id="table-useradmin-admin">
                {{# if(d.status =='3') { }}
                <a class="layui-btn layui-bg-orange layui-btn-sm"  lay-event="recharge"> <i class="layui-icon layui-icon-ok"></i></a>
                {{# }else if((d.status =='1' || d.status =='4') && d.channel=='2'){ }}
                  <a class="layui-btn layui-bg-orange layui-btn-sm"  lay-event="pay">付款</a>
                {{# } }}
            </script>
            <script type="text/html" id="table-useradmin-status">
                {{# if(d.status =='1') { }}
                <span style="color: #00ff4c">已审核</span>
                {{# }else if(d.status =='4'){ }}
                <span style="color: red">提现异常</span>
                {{# }else if(d.status =='2'){ }}
                <span style="color: #007bff">已付款</span>
                {{# } }}
            </script>
            <script type="text/html" id="table-sumprice">
                <span>兑换总金额：<b id="sumprice" style="color: red"></b></span>
            </script>
        </div>
    </div>
</div>

<script src="__PUBLIC__/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '__PUBLIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table','laydate'], function(){
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table,laydate = layui.laydate;

        //时间范围
        laydate.render({
            elem: '#start'
            ,type: 'datetime'
        });
        //时间范围
        laydate.render({
            elem: '#end'
            ,type: 'datetime'
        });

        $(".layuiadmin-btn-admin").on("click",function(){
            var startime = $("#start").val();
            var endtime = $("#end").val();
            var gameid = $("input[name=gameid]").val();
            var channel = $("select[name=channel]").val();
            table.reload('admin_table',{
                page:{
                    curr:1
                }
                ,where:{startime:startime,endtime:endtime,gameid:gameid,channel:channel}
            });
        });

        var tradetype = $("input[name=tradetype]").val();

        //执行一个 table 实例
        table.render({
            elem: '#admin_table'
            ,url: '/Bankrecored/getexchange' //数据接口
            ,title: '用户管理'
            ,page: true //开启分页
            ,toolbar: '#table-sumprice' //开启工具栏，此处显示默认图标，可以自定义模板，详见文
            ,defaultToolbar:['filter','exports']
            ,height:650
            ,totalRow:true
            ,cols: [[ //表头
                {field: 'gameid', title: '游戏ID', width:100}
                ,{field: 'name', title: '用户姓名', width:140}
                ,{field: 'channelname', title: '兑换渠道', width:120}
                ,{field: 'exaccount', title: '兑换账号', width:160,totalRowText:'<span style="color: red">兑换总金额（元）</span>'}
                ,{field: 'price', title: '兑换金额/元', width:100,totalRow:true}
                ,{field: 'charge', title: '手续费/元', width:100,totalRow:true}
                ,{field: 'time', title: '兑换时间', width:200}
                ,{field: 'status', title: '状态', width:100,toolbar: '#table-useradmin-status'}

                ,{field: 'handletime', title: '操作时间', width:200}
                ,{field: 'handlename', title: '操作人', width:120}
                ,{field: 'text', title: '备注', width:120}
                ,{field: 'status', align:'center', width:200,toolbar: '#table-useradmin-admin'}
            ]]
            ,where:{tradetype:tradetype}
            ,done:function (d) {
                $('.layui-table-total .layui-table-cell').css('color','red');
                $('.layui-table-total .layui-table-cell').css('background-color','#05e1ff');
                var sum = d['sumprice'];
                $('#sumprice').text(sum);
            }
        });


        //监听行工具事件
        table.on('tool(admin_table)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'recharge'){
                layer.prompt({
                    title:'审核通过，备注'
                    ,formType:2
                },function (text,index) {
                    // layer.msg('输入文本：'+text);
                    var id = data.id;
                    $.ajax({
                        type:'get',
                        dataType:"json",
                        url:'exchange_pass?id='+id+"&text="+text+'&status=1',
                        success:function (data) {
                            if(data['code'] == 1){
                                layer.msg(data['msg'], {icon: 1,end:function () {
                                        layer.close(index);
                                        layui.table.reload("admin_table");
                                    }});
                            }else{
                                layer.msg(data['msg'], {icon: 2,end:function () {
                                        layer.close(index);
                                        layui.table.reload("admin_table");
                                    }});
                            }
                            // layer.clone(index);
                            // layui.table.reload("admin_table");
                        },
                        error:function () {
                            layer.msg('发生错误', {icon: 2});
                        },
                    });
                })
            } else if(obj.event === 'info'){
                layer.prompt({
                    title:'审核未通过，拒绝理由'
                    ,formType:2
                },function (text,index) {
                    layer.msg('输入文本：'+text);
                    layer.clone(index);
                    $.ajax({
                        type:'post',
                        dataType:"json",
                        url:'updates',
                        data:field,
                        success:function (data) {
                            if(data['code'] == 1){
                                layer.msg(data['msg'], {icon: 1,end:function () {
                                        layui.table.reload("admin_table");
                                    }});
                            }else{
                                layer.msg(data['msg'], {icon: 2,end:function () {
                                        layui.table.reload("admin_table");
                                    }});
                            }

                        },
                        error:function () {
                            layer.msg('发生错误', {icon: 2});
                        },
                    });
                })

            }else if(obj.event === 'pay'){
                var id = data.id;
                layer.confirm('注意资金安全，确认付款吗？', function(index){
                    $.ajax({
                        type:'get',
                        dataType:"json",
                        url:'payment?id='+id,
                        success:function (data) {
                            if(data['code'] == 1){
                                layer.msg(data['msg'], {icon: 1,end:function () {
                                        layui.table.reload("admin_table");
                                    }});
                            }else{
                                layer.msg(data['msg'], {icon: 2,end:function () {
                                        layui.table.reload("admin_table");
                                    }});
                            }
                        },
                        error:function () {
                            layer.msg('发生错误', {icon: 2});
                        },
                    });
                });
            }
        });
    });
</script>
</body>
</html>